OPC Functions

 

Number SubscribeToTag(name: string, updateRate: number, equipment: object, callback: function);

Called to subscribe to a notification of a state change of a tag.

 

Name Type Description
name String The tag name, this must exist within the tag manager. The name is case sensitive
updaterate Number The number of milliseconds that represents the desired update rate of the subscription
equipment Object An object that is associated with the subscription, this object will be the 'this' reference within the callback function. If no object is required then 'null' may be passed, this will cause the 'this' reference to refer to the global object
callback function Reference to the callback function that will be invoked when an update occurs

The return value is a numeric identifier that is unique for this subscription, it may be saved for later use. It a required parameter of the function used to unsubscribe to updates

void UnSubscribeToTag(id: number);

Called to unsubscribe to state change notification

 

Name Type Description
id Number The return value from a previous call to 'SubscribeToTag'. The value uniquely identifies the subscription to the system

The return value is void

void xxxxxxxxxxxxxxxxx (name: string, id: number, value: object, quality: number);

The function that is to be invoked when a tag state change occurs

Name Type Description
name String The tag name
id Number The unique number returned from the call to 'SubscribeToTag'
value Object The new value of the tag
quality Number The quality value associated with the tag update. See below table for quality values

This function is expected to return void. The 'this' reference within the function scope will refer to the object passed in as the third parameter to 'SubscribeToTag', if this value was null, the 'this' reference refers to the global object

 

OPC DA Tag quality values

Hex Decimal Description
0x00 0 OPC_QUALITY_BAD
0x40 64 OPC_QUALITY_UNCERTAIN
0xC0 192 OPC_QUALITY_GOOD
0x04 4 OPC_QUALITY_CONFIG_ERROR
0x08 8 OPC_QUALITY_NOT_CONNECTED
0x0C 12 OPC_QUALITY_DEVICE_FAILURE
0x10 16 OPC_QUALITY_SENSOR_FAILURE
0x14 20 OPC_QUALITY_LAST_KNOWN
0x18 24 OPC_QUALITY_COMM_FAILURE
0x1C 28 OPC_QUALITY_OUT_OF_SERVICE
0x20 32 OPC_QUALITY_WAITING_FOR_INITIAL_DATA
0x44 68 OPC_QUALITY_LAST_USABLE
0x50 80 OPC_QUALITY_SENSOR_CAL
0x54 84 OPC_QUALITY_EGU_EXCEEDED
0x58 88 OPC_QUALITY_SUB_NORMAL
0xD8 216 OPC_QUALITY_LOCAL_OVERRIDE

While these values apply to OPC DA the same values are also mapped to OPC UA

void SetTagValue(id: number, value: object);

Called to modify the value of a tag

Name Type Description
id Number The unique number returned from the call to 'SubscribeToTag'
value Object The new value of the tag

The return value is void

 

OR

 

void SetTagValue(name: string, value: object); Sym3 7.14

Called to modify the value of a tag

 

Name Type Description
name String The name of the tag
value Object The new value of the tag

The return value is void

 

 

Example:

var _tag1;

function OnSimulationStart()
{
	//-- subscribe to tag
	_tag1 = SubscribeToTag("Tag1", 500, null, Tag1ValueChanged)

	//-- set value = 5
	SetTagValue(_tag1, 5);
}

function Tag1ValueChanged(name, id, value, quality)
{
	if(quality == 192) // GOOD
	{
		LogDebug("New value for " + name + ": " + value)
	}
	else
	{
		LogError("Tag '" + name + "' has a bad quality: " + quality)
	}
}

function OnSimulationStop()
{
	//-- example to unsubscribe to Tag1
	UnSubscribeToTag(_tag1);
}			

 

Example: Sym3 7.14


SetTagValue("Tag2","value");//set string value 
SetTagValue("Tag3",false); // set boolean value 
SetTagValue("Tag4",28.45);// set double value

object GetTagValue(name: string); Sym3 7.14

Called to get the value of a tag

 

Name Type Description
name String The name of the tag

The return value is Object with tag

 

Example:

var tag2Result = GetTagValue("Tag2"); //tag value by name

object GetTagValue (id: number); Sym3 7.14

Called to get the value of a tag

 

Name Type Description
id Number The subscribed id of the tag

The return value is Object with tag

Example:

var tagID = SubscribeToTag("Tag1", 500, null, Tag1ValueChanged
var tag1Result = GetTagValue(tagID);// tag value by tag id